<template>
	<view class="ChangeNickname">
		<view class="box">
			<view class="input">
				<m-input class="m-input" type="text" v-model="nickname" placeholder="请输入昵称"></m-input>
			</view>
		</view>
		<view class="btn">
			<button type="primary" @click="modify">立即修改</button>
		</view>
	</view>
</template>

<script>
	import mInput from '../../components/m-input.vue'
	export default {
		components: {
			mInput
		},
		data() {
			return {
				nickname: ''
			};
		},
		onLoad: function() {

		},
		methods: {
			modify: function() {
				if (!this.nickname) {
					this.showtoast("请输入昵称")
					return false;
				}
				//修改昵称
				const data = {
					nick_name: this.nickname
				}
				this.$request.post("/api/user/setNickName", {
						data: data
					})
					.then(res => {
						this.showtoast(res.data.msg)
						if (res.data.code == 1) {
							uni.reLaunch({
								url: '../my/my',
							});
						}
					})
					.catch(error => {
						console.error('error:', error);
					});
			},
			showtoast: function(text) {
				uni.showToast({
					title: text,
					icon: "none",
					duration: 2000
				});
			}
		}
	}
</script>

<style lang="less">
	.ChangeNickname {
		width: 100%;
		display: flex;
		flex-direction: column;
		border-top: 5px solid #F1F1F1;

		.box {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;

			.input {
				width: 90%;
				height: 50px;
				border-bottom: 1px solid #ddd;
				display: flex;
				align-items: center;
				font-size: 14px;
			}
		}

		.btn {
			height: 80px;
			width: 80%;
			margin: 0 auto;
		}
	}
</style>
